require "import"
import "tools"
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS).setStatusBarColor(0xff4DB6AC)
activity.setContentView("fileDetail_")

function exe(command)
  require "import"
  import "java.io.*"
  local cmd=luajava.astable(String(tostring(activity.getFilesDir()).."/ffmpeg "..command).split(" "))
  local process=Runtime.getRuntime().exec(cmd)
  local err=BufferedReader(InputStreamReader(process.getErrorStream()))
  function readError(err)
    require "import"
    import "java.io.*"
    local info=""
    line=err.readLine()
    while line~=nil do
      info=info.."\n"..line
      line=err.readLine()
      call("back","progress",line)
    end
    call("back","done",info)
    this.quit()
  end
  thread(readError,err)
end
function back(b,a)
  if a~=nil
    msg.text=msg.text.."\n\n"..a
  end
end
iDir. onClick=function()
  ChoiceFile(LUA_SD,function(dir)
    iDir.text=dir
    msg.text=""
    command="-hide_banner -i "..dir
    exe(command,"back")
  end)
end
preview.background=btBackground
preview. onClick=function()
  local f=File( iDir.text)
  if f.exists()
    activity.startActivity( Intent() .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .setAction(Intent.ACTION_VIEW) .setDataAndType(Uri.fromFile(f), MimeTypeMap.getSingleton().getMimeTypeFromExtension( tostring(f.Name):match("%.(.+)"))))
   else
    print("文件不存在")
  end
end


preview.background=btBackground
preview. onClick=function()
  local f=File( iDir.text)
  if f.exists()
    activity.startActivity( Intent() .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .setAction(Intent.ACTION_VIEW) .setDataAndType(Uri.fromFile(f), MimeTypeMap.getSingleton().getMimeTypeFromExtension( tostring(f.Name):match("%.(.+)"))))
   else
    print("文件不存在")
  end
end